<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>The Store Hierarchy and Ancestry</title>
    <style type="text/css">
      @import "../../../dijit/themes/claro/claro.css";
      @import "../../../dijit/themes/claro/document.css";
      @import "../../../dijit/tests/css/dijitTests.css";
      @import "../../themes/claro/claro.css";
    </style>

    <script type="text/javascript">
      var dojoConfig = {
            baseUrl: "../../../",
            packages: [
              { name: "dojo",  location: "dojo" },
              { name: "dijit", location: "dijit" },
              { name: "cbtree",location: "cbtree" }
            ]
      };
    </script>

    <script type="text/javascript" src="../../../dojo/dojo.js"></script>
    <script type="text/javascript">
      require([
        "dojo/ready",
        "cbtree/Tree",                     // Checkbox tree
        "cbtree/model/TreeStoreModel",     // Object Store Tree Model
        "cbtree/store/Hierarchy",          // The Hierarchy store
        "cbtree/store/extensions/Ancestry"
        ], function ( ready, Tree, TreeStoreModel, Hierarchy, Ancestry) {

          var store = new Hierarchy( { url: "../../store/json/Simpsons.json", idProperty:"name"});
          var model = new TreeStoreModel( { store: store,
                                             query: {name: "Root"},
                                             rootLabel: "The Family",
                                             checkedRoot: true
                                           });

          function checkBoxClicked( item, nodeWidget, event ) {
            var descendants = store.getDescendants(item);
            var ancestors   = store.getAncestors(item, true);
            var siblings    = store.getSiblings(item);

            var isDecendant = store.isDescendantOf(item,"Abe");
            var isAncestor  = store.isAncestorOf("Abe", item);

            var paths = store.getPaths( item );
            if (paths.length) {
              var intersect = paths.intersect();
              var contains  = paths.contains( /Abe/);
              var segments  = paths.segments();
            }
          }

          store.ready( function () {
            // Analyze the store hierarchy
            var broken = this.analyze();
          });

          ready (function () {
            var tree = new Tree( { model: model, id:"tree20" }, "CheckboxTree" );
            tree.on( "checkBoxClick", checkBoxClicked);
            tree.startup();
          });
        });
      </script>

  </head>

  <body class="claro">
    <h1 class="DemoTitle">Store Hierarchy and Ancestry</h1>
    <div id="CheckboxTree">
    </div>
  </body>
</html>